﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Configuration;
using KingSite.Shop.Core.Configuration;

namespace KingSite.Shop.Core.Mvc {
    public abstract class BaseController :Controller {

        private static object lockObject = new object();

        private static ShopViewEngine currentViewEngine;

        public BaseController()
        {
            string Theme = ConfigSetting.Theme;
            if (currentViewEngine == null)
            {
                lock (lockObject)
                {
                    if (currentViewEngine == null)
                    {
                        currentViewEngine = new ShopViewEngine(Theme);
                        ViewEngines.Engines.Add(currentViewEngine);
                    }
                }
            }
            ViewData["Theme"] = currentViewEngine.ThemeName;
            ViewData["ThemePath"] = string.Format("/Theme/{0}", Theme);
        }

        protected string ThemeName
        {
            get { return currentViewEngine.ThemeName; }
            set
            {
                currentViewEngine.ThemeName = value;
            }
        }

        
    }
}
